//
//  FCChoiceRadiusTableViewCell.m
//  webViewLocal
//
//  Created by wjc on 2021/3/3.
//

#import "FCChoiceRadiusTableViewCell.h"
#import "WJCDefine.h"
@implementation FCChoiceRadiusTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(16, 12, 150, 20)];
        self.titleLabel.font=font15;
        self.titleLabel.textColor=HEXC(0x232323);
       
        self.titleLabel.text=@"";
        [self.contentView addSubview: self.titleLabel];
        self.btnView = [[UIView alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+16, 7, WJCScreenW-(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+(self.accessoryType==UITableViewCellAccessoryDisclosureIndicator?56:36)), 30)];
        [self.contentView addSubview: self.btnView];
       
    }
    return self;
}
-(void)setRightBtns:(NSMutableArray<UIButton *> *)rightBtns{
    _rightBtns = rightBtns;
    CGFloat btnx =0;
    for (UIButton*btn in rightBtns) {
        if (btn.imageView.image) {
            btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            [btn setImageEdgeInsets:UIEdgeInsetsMake(0, -2, 0, 2)];
            [btn sizeToFit];
        }
        btnx+=btn.width+15;
    }
     self.btnView.width = btnx;
    CGFloat btny = 5;
    [self.btnView removeChildViews];
    for (int i = rightBtns.count-1; i>=0; i--) {
       
        
        [rightBtns[i] addTarget:self action:@selector(btnSelect:) forControlEvents:UIControlEventTouchUpInside];

        
        if (rightBtns[i].imageView.image) {
            rightBtns[i].contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            [rightBtns[i] setImageEdgeInsets:UIEdgeInsetsMake(0, -2, 0, 2)];
            [rightBtns[i] sizeToFit];
            rightBtns[i].height = 20;
        }
        
        [self.btnView addSubview:rightBtns[i]];
        btnx -= rightBtns[i].width+15;
        rightBtns[i].x = btnx;
        rightBtns[i].y = btny;
        rightBtns[i].tag = i;
        
    }
    
}
-(void)setfit{
//    [self.titleLabel sizeToFit];
//    if (self.titleLabel.right>WJCScreenW*0.7-32) {
//        self.titleLabel.right=WJCScreenW*0.7-40;
//    }
    self.btnView.x = WJCScreenW-(self.accessoryType==UITableViewCellAccessoryDisclosureIndicator?36:16)-self.btnView.width;
    self.titleLabel.width = WJCScreenW- WJCScreenW-(self.accessoryType==UITableViewCellAccessoryDisclosureIndicator?36:16)-self.btnView.width-16;
    self.titleLabel.x = 16;
//    self.btnView.frame = CGRectMake(self.titleLabel.right+16, 7, WJCScreenW-self.titleLabel.right+(self.accessoryType==UITableViewCellAccessoryDisclosureIndicator?56:36),30); //= [[UIView alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+16, 7, WJCScreenW-(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+(self.accessoryType==UITableViewCellAccessoryDisclosureIndicator?56:36)), 30)];
}
-(void)btnSelect:(UIButton*)sender{
    if (self.unionChoiced) {
        for (UIButton* sender in self.rightBtns) {
            sender.selected = NO;
        }
        sender.selected = YES;
    }else{
        sender.selected =!sender.selected;
    }
    if (self.idBlock) {
        for (UIButton *btn in self.rightBtns) {
            if (btn.selected) {
                self.idBlock(btn);
            }
        }
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
